﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NasuTek.Shion.Agent;
using System.Threading;
using System.IO;
using Skybound.Gecko;
using System.Xml.Serialization;
using System.Xml;
using System.Diagnostics;
using NasuTek.Shion.Extencibility;
using System.Resources;
using System.Text.RegularExpressions;

namespace NasuTek.Shion
{
    public partial class Form1
    {
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (SendBar.Text.ToCharArray()[0] != '/')
                {
                    Clients[em.activeServer].SendMessage(SendType.Message, em.activeChannel, SendBar.Text);
                    if (PrevMessages.DropDownItems.ContainsKey(SendBar.Text) == false)
                    {
                        ToolStripMenuItem item = new ToolStripMenuItem(SendBar.Text);
                        item.Name = SendBar.Text;
                        PrevMessages.DropDownItems.Add(item);
                    }
                    else
                    {
                        PrevMessages.DropDownItems.RemoveByKey(SendBar.Text);
                        ToolStripMenuItem item = new ToolStripMenuItem(SendBar.Text);
                        item.Name = SendBar.Text;
                        //PrevMessages.DropDownItems.Add(item);
                    }
                    /*if (PrevMessages.DropDownItems.Count == 6)
                    {
                        PrevMessages.DropDownItems.RemoveAt(0);
                    }*/
                }
                else
                {
                    string[] textmodesplit = SendBar.Text.Split(' ');

                    switch (SendBar.Text.Substring(1).Split(' ')[0])
                    {
                        case "clear":
                            ChannelText[em.activeServer][em.activeChannel] = new string[] { };
                            RefreshWindow();
                            break;
                        case "clearall":
                            ClearAll(new List<string>());
                            RefreshWindow();
                            break;
                        case "debug":
                            if (textmodesplit[1] == "raw")
                            {
                                if (textmodesplit[2] == "on") { DebuggingServers.Add(em.activeServer); }
                                else if (textmodesplit[2] == "off") { DebuggingServers.Remove(em.activeServer); }
                                
                            }
                            break;
                        default:
                            Executer.Execute(em, SendBar.Text);
                            break;
                    }
                }
            }
            catch (IndexOutOfRangeException) { }
            SendBar.Text = string.Empty;
        }
    }
}